package pckDao;

import java.io.Serializable;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
import pckEntidad.Rol;
import pckUtil.Conexion;

public class RolDao implements Serializable {

    private Conexion oConexion=new Conexion();
    private Rol oRol;
    private List<Rol> lisRol=null;

   public void insertar(Rol oRol){
         String sql = "{call sping_Rol(?,?)}";
         CallableStatement cst;
        try {
            cst = oConexion.getConnection().prepareCall(sql);
            cst.setString(1, oRol.getNombrol());
            cst.setString(2, oRol.getDescrol());
            cst.execute();            
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());
        }   
     }
    
    
    public List<Rol> listar(){
    String sql = "{call splis_Rol}";
        try {
            CallableStatement cst = oConexion.getConnection().prepareCall(sql);
            ResultSet rst = cst.executeQuery();
            lisRol= new ArrayList<Rol>();
            while(rst.next()){
                oRol = new Rol();
                oRol.setIdrol(rst.getString(1));
                oRol.setNombrol(rst.getString(2));  
                oRol.setDescrol(rst.getString(3));
                lisRol.add(oRol);
            }
            return  lisRol;
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());
        }
         return null;
     }
    
    
    public void actualizar(Rol oRol){
        try {
            String sql = "{call spact_tblRol(?,?,?)}";
            CallableStatement cst = oConexion.getConnection().prepareCall(sql);
            cst.setString(1, oRol.getIdrol());
            cst.setString(2, oRol.getNombrol());
            cst.setString(3, oRol.getDescrol());
            cst.execute();
            
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());
        }
     }
    
    
}
